﻿Namespace My

    ' The following events are available for MyApplication:
    ' 
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication

        Public Shared MyAppsCache As Cache.CacheExt

        Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
            Try
                MyAppsCache = New Cache.CacheExt()
            Catch ex As Exception
                Throw New Exception("Cannot Create Global Cache Object", ex)
            End Try

            Try
                If Not System.IO.Directory.Exists(DeskTopManager.ApplicationDataFolder) Then
                    System.IO.Directory.CreateDirectory(DeskTopManager.ApplicationDataFolder)
                End If
            Catch ex As Exception
                Throw New Exception(String.Format("Cannot Create Folder : {0}", DeskTopManager.ApplicationDataFolder), ex)
            End Try
        End Sub

        Private Sub MyApplication_UnhandledException(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.UnhandledExceptionEventArgs) Handles Me.UnhandledException
            Dim msg As String = String.Format("{0}{1}{1}{2}{1}{3}{1}{4}{1}{5}", " Unhandled Application exception ", vbCrLf, e.Exception, e.Exception.InnerException, e.Exception.Source, e.Exception.StackTrace)
            Dim ex As Exception = New Exception(msg)

            If MessageWindow.ShowMessage(ex) = DialogResult.OK Then
                'Outstandingissue: Géré le curseur pour le remettre normal... souvent il reste wait...
                'ici on a pas accès a la form...
                e.ExitApplication = False
            Else
                e.ExitApplication = True
            End If
        End Sub
    End Class

End Namespace

